package com.esyoga.yoyoga.service.impl;

import com.esyoga.yoyoga.mapper.TGymMapper;
import com.esyoga.yoyoga.pojo.TGym;
import com.esyoga.yoyoga.pojo.TGymExample;
import com.esyoga.yoyoga.pojo.TStudent;
import com.esyoga.yoyoga.pojo.TStudentExample;
import com.esyoga.yoyoga.service.GymVerifyService;
import lombok.Data;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Data
@Service
public class GymVerifyServiceImpl implements GymVerifyService {
    @Resource
    private TGymMapper tGymMapper;
    /**
     * 场馆注册
     *
     * @param phoneNumber
     * @param password
     * @return
     */
    @Override
    public int gymRegister(String phoneNumber, String password) {
        TGym tGym = new TGym();
        tGym.setgAccount(phoneNumber);
        tGym.setgPassword(password);
        tGym.setgImage("/iamge");
        int i = tGymMapper.insertSelective(tGym);
        return i;
    }

    /**
     * 通过场馆手机号查密码
     *
     * @param phone
     * @return
     */
    @Override
    public String findTGymPasswordByPhone(String phone) {
        String password = null;
        TGymExample tGymExample = new TGymExample();
        //通过Criteria构造查询条件
        TGymExample.Criteria criteria = tGymExample.createCriteria();
        criteria.andGAccountEqualTo(phone);
        List<TGym> list = tGymMapper.selectByExample(tGymExample);
        if (list.size() != 0) {
            TGym tGym = list.get(0);
            password = tGym.getgPassword();
        }
        return password;
    }

    /**
     * 通过场馆手机号查场馆信息
     *
     * @param phone
     * @return
     */
    @Override
    public TGym findTgymByPhone(String phone) {
        TGym tGym = null;
        TGymExample tGymExample = new TGymExample();
        //通过Criteria构造查询条件
        TGymExample.Criteria criteria = tGymExample.createCriteria();
        criteria.andGAccountEqualTo(phone);
        List<TGym> list = tGymMapper.selectByExample(tGymExample);
        if (list.size() != 0) {
            tGym = list.get(0);
        }
        return tGym;
    }

    /**
     * 完善场馆信息
     *
     * @param tGym
     * @return
     */
    @Override
    public int gymAddInfo(TGym tGym) {
        TGymExample tGymExample = new TGymExample();
        TGymExample.Criteria criteria = tGymExample.createCriteria();
        criteria.andGAccountEqualTo(tGym.getgAccount());
        int i = tGymMapper.updateByExampleSelective(tGym, tGymExample);
        return i;
    }

    /**
     * 用户重置密码
     *
     * @param restPhone
     * @param restPassword
     * @return
     */
    @Override
    public int resetPassword(String restPhone, String restPassword) {
        TGymExample tGymExample = new TGymExample();
        TGymExample.Criteria criteria = tGymExample.createCriteria();
        criteria.andGAccountEqualTo(restPhone);
        TGym tGym = new TGym();
        tGym.setgAccount(restPhone);
        tGym.setgPassword(restPassword);
        int i = tGymMapper.updateByExampleSelective(tGym, tGymExample);
        return i;
    }

}
